__author__ = 'zhengxiaoyu'
import xlrd
import os
import sys
import commands
stuid_set = []

data_1 = xlrd.open_workbook('class1-3_1.xlsx')
table_1 = data_1.sheets()[0]
for i in range(len(table_1.col_values(0))):
    if i >1:
        stuid_set.append(table_1.col_values(0)[i])

data_2 = xlrd.open_workbook('class1-3_2.xlsx')
table_2 = data_2.sheets()[0]
for i in range(len(table_2.col_values(0))):
    if i >1:
        stuid_set.append(table_2.col_values(0)[i])

data_3 = xlrd.open_workbook('class4-6_1.xlsx')
table_3 = data_3.sheets()[0]
for i in range(len(table_3.col_values(0))):
    if i >1:
        stuid_set.append(table_3.col_values(0)[i])

data_4 = xlrd.open_workbook('class4-6_2.xlsx')
table_4 = data_4.sheets()[0]
for i in range(len(table_4.col_values(0))):
    if i >1:
        stuid_set.append(table_4.col_values(0)[i])

id_set = []
name_set = []

postfix = sys.argv[1]

data_5 = xlrd.open_workbook('exception-name-1-3.xlsx')
table_5 = data_5.sheets()[0]
for i in range(len(table_5.col_values(0))):
    if i > 0:
        id_set.append(table_5.col_values(0)[i])
        name_set.append(table_5.col_values(2)[i])

data_6 = xlrd.open_workbook('exception-name-4-6.xlsx')
table_6 = data_6.sheets()[0]
for i in range(len(table_6.col_values(0))):
    if i > 0:
        id_set.append(table_6.col_values(0)[i])
        name_set.append(table_6.col_values(2)[i])

# For the students whose git username are not standard.
for i in range(len(id_set)):
    cmd = "git clone git@git.oschina.net:%s/%s.git homeworks/%s_%s" % (name_set[i], postfix, id_set[i], postfix)
    os.system(cmd);

# For the students whose git username are standard.
stuid_set = set(stuid_set)
for i in stuid_set:
    cmd = "git clone git@git.oschina.net:iss%s/%s.git homeworks/%s_%s" % (i, postfix, i, postfix)
    os.system(cmd);